<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>系统角色管理页</title>
</head>
<%
	String path = request.getContextPath();
	request.setAttribute("path", request.getContextPath());
	request.setAttribute("jsPath", path+"/js");
%>
<%
	if(request.getAttribute("list") == null){
		response.sendRedirect(request.getContextPath()+"/sysRole/delete");
	}
%>
<style type="text/css">
	
	#add {
	width: 100px;
	height: 30px;
	border: 1px solid black;
	background-color: #0072CC;
	text-align: center;
	line-height: 30px;
	position: absolute;
	left: 350px;
	top: 300px;
}
a {text-decoration: none;}
#yeshu {
	margin-left: 400px;
	margin-top: 35px;
}
#delete {
    background-color: #0072CC;
	width: 100px;
	height: 30px;
	border: 1px solid black;
	text-align: center;
	line-height: 30px;
	color:white;
}
#update {
	width: 100px;
	height: 30px;
	border: 1px solid black;
	text-align: center;
	line-height: 30px;
	position: absolute;
	left: 950px;
	top: 300px;
	background-color: #0072CC;
}
#baise{color: white;}

#query{
            text-align: center;
        }
        
table{ width:100%; text-align:center; }  

#information{
   background-color: #0072CC;
   border: 1px solid black;
   color:white;
}

</style>
<script type="text/javascript" src="${jsPath}/jquery-1.8.3.min.js"></script>
<script type="text/javascript" src="${jsPath}/global.js"></script>
<script type="text/javascript" src="${jsPath}/timer.js"></script>
<script type="text/javascript">
$(function(){
	$("#checkall").click(function () {
		var ischecked = this.checked;
		   $("input:checkbox[name='guids']").each(function () {
		         this.checked = ischecked;
		     });
		 });
	});
	
	function search(){
		$("#pageIndex").val(1);
		$('#searchForm').submit();
	}
	
	function goPage(pageIndex){
		$("#pageIndex").val(pageIndex);
		$('#searchForm').submit();
	}
	
	$(function(){
		$("#myPageIndex").blur(function(){
			var myPageIndex = parseInt($(this).val());
			var totalPage = parseInt($("#totalPage").html());
			var reg = /\d/;
			if(reg.test(myPageIndex) == false){
				$(this).val(1);
			}
			if(myPageIndex > totalPage){
				$(this).val(totalPage);
			}
		});
	});
	
	function chk() {
        var obj = document.getElementsByName('guids'); //选择所有name="'test'"的对象，返回数组
        //取到对象数组后，我们来循环检测它是不是被选中
        var s = '';
        for (var i = 0; i < obj.length; i++) {
            if (obj[i].checked) s += obj[i].value + ','; //如果选中，将value添加到变量s中
        }
        //那么现在来检测s的值就知道选中的复选框的值了
        //alert(s == '' ? '你还没有选择任何内容！' : s);
        if(s == ''){
        	alert('你还没有选择任何内容！');
        }
        
       $.ajax({
			type:"GET",
			url:"<%=path%>/sysRole/ajax",
			data:{id:s},
			dataType:"json",
			success:function(result){
				window.location.href='<%=path%>/sysRole/get';
			},error:function($data){
				window.location.href='<%=path%>/sysRole/get';
			}
		});
   }
</script>
<body>
	<c:if test="${not empty sysRoleVo.msg}"><p style="display:none" id="msg">${sysRoleVo.msg}</p></c:if>
	<form action="${path}/sysRole/delete" method="get" id="searchForm">
		<p id="query"><strong>用户名(支持模糊查询)</strong>
			<input type="text" name="name" value="${sysRoleVo.name}"/> <strong>创建时间</strong>
			  <input type="text" name="beginDate" id="beginDate" placeholder="请选择开始时间" 
				readonly="readonly" onclick="SelectDate(this,'yyyy-MM-dd hh:mm:ss')"/> — 
			 <input type="text" name="endDate" id="endDate" placeholder="请选择结束时间" 
				readonly="readonly" onclick="SelectDate(this,'yyyy-MM-dd hh:mm:ss')"/>
			 <input type="hidden" id="pageIndex" name="pageIndex" value="${sysRoleVo.pageIndex}"/> 
			<input type="button" value="查找信息" onclick="search()" id="information"/>
		</p>
	</form>
	<table>
		<tr>
		    <th><input type="checkbox" id="checkall">全选</th>
			<th>序号</th>
			<th>角色ID</th>
			<th>名称</th>
			<th>创建时间</th>
			<th>是否为角色管理</th>
		 </tr>
		 <c:forEach var="sysRole" items="${list}" varStatus="status">
		 	<tr>
		 	    <td><input type="checkbox" name="guids" value="${sysRole.roleId}"></td>
		 		<td>${status.index+1}</td>
			 	<td><c:out value="${sysRole.roleId}"></c:out></td>
				<td><c:out value="${sysRole.name}"></c:out></td>
				<td><c:out value="${sysRole.createTime}"></c:out></td>
				<td>
					<c:if test="${sysRole.managerRoleFlag == 1}">是</c:if>
					<c:if test="${sysRole.managerRoleFlag == 2}">否</c:if>
				</td>
		 	</tr>
		 </c:forEach>
	</table>
	<p id="yeshu">
		<c:if test="${sysRoleVo.pageIndex>1}"><a class="btn" href="javaScript:void(0)" onclick="goPage(${sysRoleVo.pageIndex-1})">上一页</a></c:if>
		<c:if test="${sysRoleVo.pageIndex<totalPages}"><a class="btn" href="javascript:void(0)" onclick="goPage(${sysRoleVo.pageIndex+1})">下一页</a></c:if>
		--第<input id="myPageIndex" type="text" size="1" value="${sysRoleVo.pageIndex}"/>页,
		共<span id="totalPage">${totalPages}</span>页 --
		<a class="btn" href="javaScript:void(0)" onclick="goPage($('#myPageIndex').val())">跳转</a>
	</p>
	<input type="button" onclick="chk()" value="批量删除" id="delete"/>
</body>
</html>